﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Threading
{
	public static class ReadWriterLockSlimExtensions
	{

		public static IDisposable EnterReadingMode( this ReaderWriterLockSlim handle )
		{
			handle.EnterReadLock();
			return new LockCookieHelper( handle, LockMode.Read );
		}

		public static IDisposable EnterWritingMode( this ReaderWriterLockSlim handle )
		{
			handle.EnterWriteLock();
			return new LockCookieHelper( handle, LockMode.Write );
		}


		public static IDisposable EnterUpgradeableMode( this ReaderWriterLockSlim handle )
		{
			handle.EnterUpgradeableReadLock();
			return new LockCookieHelper( handle, LockMode.UpgradeToWrite );
		}

		//public static IDisposable UpgradeLock( this ReaderWriterLockSlim handle )
		//{
			
		//    return null;
		//}
	}
}
